import 'package:flutter/material.dart';
import 'package:flutter_smart_heating/common/app.dart';
import 'package:flutter_smart_heating/ui/ui.dart';

class UserMenuView extends StatelessWidget {
  const UserMenuView({super.key});

  @override
  Widget build(BuildContext context) {
    var boxShadow = UiTheme(context).match(
      light: [BoxShadow(color: Colors.grey.withOpacity(0.1), blurRadius: 10)],
    );
    return Column(
      children: [
        UiPanel(
          boxShadow: boxShadow,
          children: [
            cell(
              icon: UiIcons.safetycertificate,
              image: 'user',
              title: '个人信息',
              onTap: () {
                App.push('/user/profile');
              },
            ),
            cell(
              icon: UiIcons.safetycertificate,
              image: 'notice',
              title: '消息中心',
              onTap: () {
                App.push('/broadcast');
              },
            ),
            cell(
              icon: UiIcons.barchart,
              image: 'calendar',
              title: '数据统计',
              onTap: () {
                App.push('/summary/overall?title=数据统计&--token--',
                    openType: 'browser');
              },
            ),
            cell(
              icon: UiIcons.read,
              image: 'support',
              title: '帮助中心',
              showDivider: false,
              onTap: () {
                App.push('/support');
              },
            ),
          ],
        ),
        const UiLineBreak(),
        UiPanel(
          boxShadow: boxShadow,
          children: [
            cell(
              icon: UiIcons.info_circle,
              image: 'info',
              title: '关于我们',
              onTap: () {
                App.push('/setting/about');
              },
            ),
            cell(
              icon: UiIcons.mail,
              image: 'suguest',
              title: '反馈建议',
              onTap: () {
                App.push('/feedback');
              },
            ),
            cell(
              icon: UiIcons.setting,
              image: 'setting',
              title: '通用设置',
              showDivider: false,
              onTap: () {
                App.push('/setting');
              },
            ),
          ],
        ),
        const UiLineBreak(),
        UiPanel(
          boxShadow: boxShadow,
          children: [
            cell(
                icon: UiIcons.logout,
                image: 'logout',
                title: '退出登录',
                showDivider: false,
                onTap: () {
                  App.push('/user/logout');
                }),
          ],
        ),
      ],
    );
  }

  Widget cell({
    required IconData icon,
    required String title,
    String? image,
    Function()? onTap,
    bool showDivider = true,
  }) {
    return UiListCell(
      onTap: onTap,
      leading: image != null
          ? Image.asset(
              'res/images/icons/$image.png',
              height: 25,
              width: 25,
              fit: BoxFit.cover,
            )
          : UiLinearGradientMask(
              child: Icon(
              icon,
              color: Colors.white,
            )),
      leadingSpace: 10,
      title: Text(title),
      showArrow: true,
      showDivider: showDivider,
      dividerIndent: 50,
      backgroundColor: Colors.transparent,
    );
  }
}
